package com.tz.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;


@Entity
@Table(name="TBL_COMMODITY")
public class Commodity {

	private long id;

	private Cart cart;

	private long amount;

	private Product product;

	public Commodity() {
		
	}

	public Commodity(Cart cart, long amount, Product product) {
		super();
		this.cart = cart;
		this.amount = amount;
		this.product = product;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="s4")
	@SequenceGenerator(name="s4",sequenceName="tbl_commodity_id")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name="cart_id")
	public Cart getCart() {
		return cart;
	}

	public void setCart(Cart cart) {
		this.cart = cart;
	}

	@Column(name="c_amount")
	public long getAmount() {
		return amount;
	}

	public void setAmount(long amount) {
		this.amount = amount;
	}

	@ManyToOne
	@JoinColumn(name="product_id")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Commodity [id=");
		builder.append(id);
		builder.append(", amount=");
		builder.append(amount);
		builder.append("]");
		return builder.toString();
	}

}
